<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('减持公告信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('上市项目')" prop="listedId">
        <el-select v-model="queryParams.listedId" filterable clearable :placeholder="$t('请选择')">
          <el-option
            v-for="item in listedOptions"
            :key="item.id"
            :label="item.dealName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('标题')" prop="title">
        <el-input
          v-model="queryParams.title"
          :placeholder="$t('标题')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('公告发布时间')" prop="releaseDateArray">
        <DatePicker
          v-model="releaseDateArray"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['listed:reducing:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="listedReducingNoticeList" border>
      <el-table-column fixed="left" :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column fixed="left" :label="$t('上市项目')" align="center" prop="dealName" show-overflow-tooltip min-width="160">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.dealName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('证券代码')" align="center" prop="stockCode" show-overflow-tooltip min-width="150" />
      <el-table-column :label="$t('标题')" align="center" prop="title" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('公告内容')" align="center" prop="context" show-overflow-tooltip min-width="200" />
      <el-table-column :label="$t('减持股数不超过(万股)')" align="center" prop="shareNotExceeding" min-width="150">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.shareNotExceeding) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('减持日期区间')" align="center" prop="reducingDate" show-overflow-tooltip width="180" :formatter="reducingDateFormat" />
      <el-table-column :label="$t('预计公告发布日期')" align="center" prop="releaseDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.releaseDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <ListBtn :bus-data="scope.row" has-permi="listed:reducing" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改上市项目-减持公告对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <listedReducingNoticeForm ref="listedReducingNoticeForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listListedReducingNotice,
  delListedReducingNotice
} from '@/api/deal/listed/reducing/listedReducingNotice'
import listedReducingNoticeForm from './listedReducingNoticeForm.vue'
import { listListedDeal } from '@/api/deal/listed/base/listedDeal'
import moment from 'moment'

export default {
  components: {
    listedReducingNoticeForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 上市项目-减持公告表格数据
      listedReducingNoticeList: [],
      // 弹出层标题
      title: '减持公告',
      // 是否显示弹出层
      formOpen: false,
      // 上市项目options
      listedOptions: [],
      // 日期区间查询项
      releaseDateArray: [],
      // 交易方式字典
      tradingWayOptions: [],
      // 查询参数
      queryParams: {
        listedId: undefined,
        title: undefined,
        releaseDateStart: undefined,
        releaseDateEnd: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 上市项目查询条件
      listedQueryParam: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('listed_trading_way').then(response => {
      this.tradingWayOptions = response.data
    })
    this.listedQueryParam.dealType = (this.$route.query.dealType === undefined ? 'equity' : this.$route.query.dealType)
    listListedDeal(this.listedQueryParam).then(response => {
      this.listedOptions = response.rows
    })
  },
  methods: {
    /** 查询上市项目-减持公告列表 */
    getList() {
      this.loading = true
      if (this.releaseDateArray !== undefined) {
        if (this.releaseDateArray[0] !== null && this.releaseDateArray[0] !== undefined) {
          this.queryParams.releaseDateStart = moment(this.releaseDateArray[0]).format('YYYY-MM-DD')
        }
        if (this.releaseDateArray[1] !== null && this.releaseDateArray[1] !== undefined) {
          this.queryParams.releaseDateEnd = moment(this.releaseDateArray[1]).format('YYYY-MM-DD')
        }
      }
      this.queryParams.dealType = (this.$route.query.dealType === undefined ? 'equity' : this.$route.query.dealType)
      listListedReducingNotice(this.queryParams).then(response => {
        this.listedReducingNoticeList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 交易方式字典翻译
    tradingWayFormat(row) {
      return this.selectDictLabel(this.tradingWayOptions, row.tradingWay)
    },
    // 拼接减持日期区间
    reducingDateFormat(row) {
      return this.parseTime(row.reducingDateStart) + '~' + this.parseTime(row.reducingDateEnd)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        listedId: undefined,
        title: undefined,
        shareNotExceeding: undefined,
        rateNotExceeding: undefined,
        releaseDate: undefined,
        tradingWay: undefined,
        reducingDate: undefined,
        context: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.releaseDateArray = []
      this.queryParams.releaseDateEnd = undefined
      this.queryParams.releaseDateStart = undefined
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.listedReducingNoticeForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.listedReducingNoticeForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delListedReducingNotice(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
